I have 3 variables
let oneWord = "offering"
let twoWord = "test_offering"
let threeWord = "loan_offering_data"
I want to make where if the value of TwoWord is executed/displayed as test-offering and suppose the value of threeWord is executed/displayed it becomes loan/offering-data
how to make a function to meet the above criteria dynamic?
function reformat(word) {
const wds=word.split("_");
if (wds.length ===1) return word;
if (wds.length ===2) return wds.join("-");
if (wds.length ===3) return `${wds[0]}/${wds[1]}-${wds[2]}`;
throw new Error("too many words");
}